<?php

namespace App\Admin\Actions\Post;

use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use App\Models\CompanyJob;

class AllJobDelete extends BatchAction
{
    public $name = '批量删除';

    public function handle(Collection $collection)
    {
        foreach ($collection as $model) {
            if (!in_array($model->job_status, [-1, 0])) {
                continue;
            }

            $id = $model->id;
            $res = CompanyJob::where('id', $id)->update(['job_status' => -2]);
            if (!$res) {
                return $this->response()->error('操作失败！')->refresh();
            }
        }

        return $this->response()->success('操作成功')->refresh();
    }

    public function dialog()
    {
        $this->confirm('确定删除吗？');
    }
}